<?php
require_once('App-Top.php');
require_once('Authorizer.php');
require_once('GenFunctions.php');
require_once('DBConfigQuery.php');
require_once('../config.inc.php');
require_once('../Validation.php');

// Check if it is Member Mng
if (isset($_SESSION['SESS_USER_TYPE'])) {
    if (!isUserType_Members($_SESSION['SESS_USER_TYPE'])) {
        header("Location: AdminIndex.php");
        exit();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Treasurer Pay Confirmation</title>
        <link href="StyleControl.css" rel="stylesheet" type="text/css" />
    </head>
    <body>

        <div id="sidebar">
            <h3>Reports</h3>
            <ul>
                <li><a href="#">Gate List</a></li>
                <li><a href="#">Members List</a></li>
            </ul>


            <?php
            require_once('MenuAdmin.php');
            ?>
        </div>

        <div id="mainbody">
            <h1>Make Payment Confirmation</h1> <br />

            <form id="paymentConfirm" name="paymentConfirm" method="POST" action="AdminPayExec.php">

            <table summary="Edit Member Information" class="TSoft">

                <tr>
                    <td class="THeader">First Name</td>
                    <td class="THeader">Last Name</td>
                    <td class="THeader">Email</td>
                    <td class="THeader">Payment Change</td>
                </tr>

            <?php
            
            // Clean first
            if ( isset($_SESSION['FORMS']['FormPmtAddPmt']))
            {
                unset ($_SESSION['FORMS']['FormPmtAddPmt']);
            }
            if ( isset($_SESSION['FORMS']['FormPmtRemovePmt']))
            {
                unset ($_SESSION['FORMS']['FormPmtRemovePmt']);
            }
            // Stores the member to add payment
            $_SESSION['FORMS']['FormPmtAddPmt'] = array();
            // Stores the members to remove payment
            $_SESSION['FORMS']['FormPmtRemovePmt'] = array();

            // Insert the emails of the ones that actually changed
            if ( isset($_POST['payment']) && isset ($_SESSION['FORMS']['FormPayment']))
            {
                foreach ($_POST['payment'] as $valuePost)
                {
                    if($_SESSION['FORMS']['FormPayment'][$valuePost]['Paid'] == 0)
                    {
                        // This member has not paid and it is going to pay
                        array_push($_SESSION['FORMS']['FormPmtAddPmt'],$valuePost);
                    }
                }

                foreach ($_SESSION['FORMS']['FormPayment'] as $userElem)
                {
                    if (array_search($userElem['Email'], $_POST['payment']) === FALSE)
                    {
                        if ($_SESSION['FORMS']['FormPayment'][$userElem['Email']]['Paid'] != 0)
                        {
                            array_push($_SESSION['FORMS']['FormPmtRemovePmt'],$userElem['Email']);
                        }
                    }
                }

            }

            // Print the member to process remove payment
            foreach ($_SESSION['FORMS']['FormPmtRemovePmt'] as $valueRemove)
            {
                echo "<tr>";
                echo "<td class='TBody'>" . $_SESSION['FORMS']['FormPayment'][$valueRemove]['FirstName'] . "</td>";
                echo "<td class='TBody'>" . $_SESSION['FORMS']['FormPayment'][$valueRemove]['LastName'] . "</td>";
                echo "<td class='TBody'>" . $valueRemove . "</td>";
                echo "<td class='TBody'><font color='#CC0000'>Remove Payment</font></td>";
                echo "</tr>";
            }

            // Print the member to process add payment
            foreach ($_SESSION['FORMS']['FormPmtAddPmt'] as $valueAdd)
            {
                echo "<tr>";
                echo "<td class='TBody'>" . $_SESSION['FORMS']['FormPayment'][$valueAdd]['FirstName'] . "</td>";
                echo "<td class='TBody'>" . $_SESSION['FORMS']['FormPayment'][$valueAdd]['LastName'] . "</td>";
                echo "<td class='TBody'>" . $valueAdd . "</td>";
                echo "<td class='TBody'><font color='#00CC00'>Add Payment</font></td>";
                echo "</tr>";
            }

            ?>


            </table>

                <br />
                <input type="submit" name="PaymentConfirm" value="Confirm Payment" class="button"/>
                <input type="submit" name="PaymentBack" value="Edit Payment" class="button"/>

            </form>
        </div>

    </body>
</html>
<?php

    require_once('App-End.php');
?>

<!-- Designed: Jose Trujillo - 2011 -->